<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>

<link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/header.css"/>" />

<div class="navbar navbar-default" role="navigation">
	<div class="container">
		<div class="navbar-header">
			<a class="navbar-brand" href="<c:url value="/login"/>">Clients Manager</a>
			<security:authorize access="isAuthenticated()">
				<a class="navbar-brand" href="<c:url value="/client/list" />">View Clients</a>
			</security:authorize>
		</div>
		<ul class="nav navbar-nav navbar-right">
			<security:authorize access="isAuthenticated()">
				
				<li><a href="<c:url value="/profile/${user.userId}" />">${user.name} (ID: ${user.userId})</a></li>
				<li><a href="<c:url value="/profile/${user.userId}" />">Profile</a></li>
				<li><a href="javascript:logout()">Logout</a></li>
				
				<c:url var="logoutUrl" value="/j_spring_security_logout"/>
				<form action="${logoutUrl}" method="POST" id="logoutForm">
				  <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
				</form>
			 
				<script>
					function logout() {
						$('#logoutForm').submit();
					}
				</script>
			</security:authorize>
			
			<!-- c:if test="${empty user}"-->
			<security:authorize access="isAnonymous()">
				<li><a href="<c:url value="/login"/>">Log In</a></li>
			</security:authorize>
			<!--/c:if-->
			
		</ul>
	</div>
</div>